/*
 * SessionCheckFilter.java
 *
 * Created on 12 de marzo de 2008, 10:51 AM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package score;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author analista4
 */
public class SessionCheckFilter implements Filter {
 private static int firstRequest = 0;
 public void doFilter(ServletRequest request, ServletResponse response,
                    FilterChain chain) throws IOException, ServletException {
      HttpServletRequest hreq = (HttpServletRequest)request;
      HttpServletResponse hres = (HttpServletResponse)response;
      HttpSession session = hreq.getSession();
      if (session.isNew()) {
          if(firstRequest == 0){
               firstRequest++;
          } else {
               hres.sendRedirect("faces/SessionExpired.jsp");
               return;
          }
      }
      chain.doFilter(request, response);
  }
  public void init(FilterConfig filterConfig) throws ServletException {}
  public void destroy() {}
}